<template>
  <div class="layout">
    <el-container>
      <el-aside width="200px">
        <nav-menu></nav-menu>
      </el-aside>
      <el-main>
        <el-header>
          <div class="user">
            <img class="img" src="../../assets/a1.png" alt="" />
            <!--<span class="username">{{ userInfo.username }}</span>-->
            <el-dropdown>
              <span class="el-dropdown-link">
                {{ userInfo.username }}<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>
                  <span @click="logout">登出</span>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <div class="content">
          <router-view></router-view>
          <!--router-view是展示各个界面的关键-->
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import NavMenu from "../views/NavMenu.vue";
import { mapState, mapMutations } from "vuex";
export default {
  name: "layout",
  data() {
    return {};
  },
  computed: {
    ...mapState(["userInfo"]),
  },
  methods: {
    logout(){
      this.userlogout()
      this.$router.push('/login')
    },
    ...mapMutations(['userlogout'])
  },
  components: { NavMenu },
};
</script>

<style>
.layout {
  height: 100%;
}
.el-container {
  height: 100%;
}
.el-main {
  padding: 0;
}
.el-header {
  width: 100%;
  height: 100px;
  box-shadow: 0 0 5px #ccc;
}
.user {
  float: right;
  margin-right: 650px;
  margin-top: 20px;
}
.content {
  padding: 40px;
}
.img {
  width: 25px;
}
</style>